/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tencent.tendon.convert.json.streams;

import com.tencent.tendon.convert.json.JsonException;
import java.io.IOException;
import java.nio.CharBuffer;

/**
 *
 * @author nbzhang
 */
public class JsonStreamReader extends JsonAbstractReader {

    private final CharBuffer buffer = CharBuffer.allocate(1);

    private final char[] chars = buffer.array();

    private final Readable reader;

    public JsonStreamReader(Readable reader) {
        this.reader = reader;

    }

    @Override
    protected char get() {
        try {
            buffer.clear();
            int rs = reader.read(buffer);
            if (rs < 0) return (char) -1;
            return chars[0];
        } catch (IOException ex) {
            throw new JsonException(ex);
        }
    }
}
